<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item label="款名/款号/SKU" class="myform-item">
          <el-input
            v-model="form.title"
            placeholder="请输入款名/款号/SKU"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="颜色规格" class="myform-item">
          <el-input
            v-model="form.color_specification"
            placeholder="请输入颜色规格"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="dialogTableVisibleImport = true"
            >导入数据</el-button
          >
        </el-form-item>
      </div>
    </el-form>
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column
        label="款名"
        align="center"
        prop="product_name"
        width="300"
      >
      </el-table-column>
      <el-table-column label="款号" align="center" prop="type_no" width="100">
      </el-table-column>
      <el-table-column
        label="SKU"
        align="center"
        prop="product_code"
        width="200"
      >
      </el-table-column>
      <el-table-column label="其他信息" align="center" prop="list">
        <template slot-scope="{ row }">
          <el-table :data="row.list" style="width: 100%" border>
            <el-table-column
              label="颜色规格"
              align="center"
              prop="color_specification"
            ></el-table-column>
            <el-table-column
              label="销售数量"
              align="center"
              prop="num"
            ></el-table-column>
            <el-table-column
              label="销售金额"
              align="center"
              prop="amount"
            ></el-table-column>
            <el-table-column label="退货数量" align="center" prop="tui_num">
              <template slot-scope="{ row }">
                {{ row.tui_num || 0 }}
              </template>
            </el-table-column>
            <el-table-column
              label="退货金额"
              align="center"
              prop="tui_amount"
            ></el-table-column>
            <el-table-column
              label="退货率"
              align="center"
              prop="tui_rate"
            ></el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="{ row }">
                <el-button type="primary" @click="onDetail(row)"
                  >查看详情</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postAdminOperateGet_operate_order"
    />
    <el-dialog title="平台店铺详情" :visible.sync="dialogTableVisible">
      <div class="dialogTable">
        <div>款式名称：{{ row.product_name }}</div>
        <div>款号：{{ row.type_no }}</div>
        <div>SKU：{{ row.product_code }}</div>
        <div>颜色规格：{{ row.color_specification }}</div>
      </div>
      <el-table
        :data="dialogTable"
        border
        :header-cell-style="{ background: '#ecf1fe' }"
      >
        <el-table-column property="shop_name" label="店铺"></el-table-column>
        <el-table-column property="num" label="销售数量"></el-table-column>
        <el-table-column property="amount" label="销售金额"></el-table-column>
        <el-table-column property="tui_num" label="退货数量">
          <template slot-scope="{ row }">
            {{ row.tui_num || 0 }}
          </template>
        </el-table-column>
        <el-table-column
          property="tui_amount"
          label="退货金额"
        ></el-table-column>
        <el-table-column property="tui_rate" label="退货率"></el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog title="导入销售数据" :visible.sync="dialogTableVisibleImport">
      <div class="fileTitle">
        <div class="fileTitle-top">日期</div>
        <div>
          <el-date-picker
            v-model="daytime"
            value-format="yyyy-MM-dd"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </div>
      </div>
      <div class="fileTitle">
        <div class="fileTitle-top">数据文件</div>
        <div class="fileTitle-two">
          <div v-if="file" class="fileTitle-two-file">
            <div><i class="el-icon-tickets"></i> {{ file.name }}</div>
            <i class="el-icon-close pointer" @click="file = ''"></i>
          </div>
          <el-upload
            v-else
            class="avatar-uploader"
            action="/"
            accept=".xls, .xlsx"
            :before-upload="beforeAvatarUpload"
          >
            <i class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogTableVisibleImport = false">取 消</el-button>
        <el-button
          :disabled="!daytime || !file"
          type="primary"
          @click="onImport"
          :loading="loading"
          >导 入</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  postAdminOperateGet_operate_order,
  postAdminOperateGet_operate_order_look,
  uploadAdminExcelImport_sale_date,
} from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      dialogTableVisible: false,
      dialogTableVisibleImport: false,
      form: {
        title: "",
        color_specification: "",
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 1,
      dialogTable: [],
      row: "",
      daytime: "",
      file: "",
    };
  },
  activated() {
    let form = this.form;
    this.postAdminOperateGet_operate_order(form);
  },
  methods: {
    // 导入
    async onImport() {
      this.loading = true;
      let { daytime, file } = this;
      let obj = {
        daytime,
      };
      try {
        let data = await uploadAdminExcelImport_sale_date(file, obj);
        console.log("filedata--->", data);
        this.$message.success("导入成功");
        this.dialogTableVisibleImport = false;
        this.loading = false;
        let form = this.form;
        this.postAdminOperateGet_operate_order(form);
        
      } catch (error) {
        console.log("error--->", error);
        this.loading = false;
      }
    },
    beforeAvatarUpload(file) {
      this.file = file;
      console.log("file--->", file.name);
      return false;
    },
    // 查看详情
    async onDetail(row) {
      let obj = {
        type_no: row.type_no,
        product_code: row.product_code,
      };
      this.row = row;
      try {
        let data = await postAdminOperateGet_operate_order_look(obj);
        console.log("data", data);
        this.dialogTable = data.data;
        this.dialogTableVisible = true;
      } catch (error) {
        console.log("error", error);
      }
    },
    // qc列表
    async postAdminOperateGet_operate_order(data) {
      this.loading = true;
      this.form = data;
      let form = JSON.parse(JSON.stringify(this.form));
      if (form.create_time) {
        form.create_time = `${form.create_time[0]}/${form.create_time[1]}`;
      }
      postAdminOperateGet_operate_order(form)
        .then((res) => {
          this.loading = false;
          console.log("qc列表", res);
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postAdminOperateGet_operate_order(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.fileTitle {
  .fileTitle-top {
    font-size: 18px;
    font-weight: 600;
    margin: 10px 0;
  }
  .fileTitle-two {
    .fileTitle-two-file {
      display: flex;
      align-items: center;
      color: #67c23a;
      padding-left: 10px;
      > i {
        margin-left: 20px;
      }
    }
  }
}
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
.dialogTable {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  border-bottom: 1px solid #efefef;
  padding-bottom: 20px;
  margin-bottom: 20px;
  > div {
    padding: 0 20px;
  }
  > div:not(:nth-last-child(1)) {
    border-right: 1px solid #efefef;
  }
}
</style>
